// const viewList = import.meta.glob("/node_modules/xhyk-vue/**/*.vue", {
//   eager: true,
//   import: 'default',
// })



// region 自定义指令
// 判断
function hasPermission(permissionList, permissionCheck, lowerCase = false) {
  // Helper function to convert to lowercase if caseInsensitive is true
  const normalize = (str) => lowerCase ? str.toLowerCase() : str;

  // Normalize the permissionList if caseInsensitive is true
  const normalizedPermissionList = permissionList.map(normalize);

  if (typeof permissionCheck === 'string') {
    return normalizedPermissionList.includes(normalize(permissionCheck));
  } else if (Array.isArray(permissionCheck)) {
    return permissionCheck.some(subCheck => {
      if (typeof subCheck === 'string') {
        return normalizedPermissionList.includes(normalize(subCheck));
      } else if (Array.isArray(subCheck)) {
        return subCheck.every(subSubCheck => normalizedPermissionList.includes(normalize(subSubCheck)));
      }
      return false;
    });
  }
  return false;
}

export const setXhykDirective = (app) => {

  // region 添加显示权限指令
  // 复杂的逻辑推荐使用xhyk-power组件
  app.directive('xhyk-show', (el, binding, vnode, prevNode) => {
    const showValue = binding.value || ''
    let isShow;
    const list = window.$xhykPower || undefined
    if (list == undefined) {
      isShow = true
    } else {
      isShow = hasPermission(list, showValue, true)
    }
    if (!isShow) {
      el.style.display = 'none';
    } else {
      el.style.display = ''; // 如果之前被隐藏，恢复显示
    }
  })
  // endregion
}
// endregion